// JavaScript Document

	

 $(document).ready(function() {
	// $('.active-menu a').click(function(){return false;})	
	 
	 //script for menu-bg
	 function widthbottom(selector,childsector){ 
		 var li = $(selector).width();
		 $(childsector).css('width',li);		 
		 };
		 widthbottom('#main-menu #menu li.home','.home .button-bg');
		 widthbottom('#main-menu #menu li.menu-a','.menu-a .button-bg');
		 widthbottom('#main-menu #menu li.menu-b','.menu-b .button-bg');
		 widthbottom('#main-menu #menu li.menu-c','.menu-c .button-bg');
		 widthbottom('#main-menu #menu li.menu-d','.menu-d .button-bg');
		 widthbottom('#main-menu #menu li.menu-e','.menu-e .button-bg');
	 
	 $('#main-menu #menu li').hover(
	 function(){
		 $(this).addClass('menu-on-hover');
		 },
	function(){
		 $(this).removeClass('menu-on-hover');
		 }	 
	 )
	 
	 
	 //according menu
	 
	$('.list2').slideUp();
	
	
	 $('.click-on').click(
	 	function(){
			$('.list2').slideUp();
			if($(this).parent().find('.list2').css('display')=='none'){$(this).parent().find('.list2').slideDown();
			$(this).parent().css('background','url(../images/arrowdown.png) 8px 12px no-repeat')
			}
			else{$('.list2').slideUp();
			$(this).parent().css('background','url(../images/arrow-left.png) 8px 12px no-repeat')
			}
			}
	 );
		 //can giua logo;
	 
	  var divheight = $('.logodoitac').height();
	  var logoheight = $('.logodoitac img').height();
	  var marginTop = (divheight -logoheight)/2;
	  $('.logodoitac img').css('margin-top',marginTop);
	  
	  //su kien hover vao logo thi co hieu ung say ra
	  
	  
	  $('.doitac').hover(function(){
		  	var logowidth = $(this).find('.logodoitac img').width();
			var thua = logowidth -30;
			var currentWidth = $(this).find('.logodoitac').width();
		 	$(this).find('.logodoitac').stop().animate({width: logowidth, marginLeft: 0 - thua +'px'});		 	
			$(this).find('.chitietdoitac').stop().animate({width: 180});
		  },function(){
				$('.logodoitac').stop().animate({width: 210 +'px', marginLeft:0});
				$('.chitietdoitac').stop().animate({width: 0});  
		  }
	  );
	

	  
	  
	  
	  
	  
	  
	  
	  
	  		$('#thums1').addClass('active');
	  		$("#slider").carouFredSel({
				items		: 1,
				auto :true,
				pauseOnHover: true,
				scroll	: {
					//
					pauseDuration : 5000,
					onBefore: function(oldItems, newItems) {
						var newID = $(newItems).attr('alt');
						var oldID = $(oldItems).attr('alt');
						$('#' + newID).addClass('active');						
						$('#' + oldID).removeClass('active');
					}
				},
				pagination  : "#foo3_pag"				
			});
			
			$("#slider").trigger("linkAnchors", ["#slide-content a", "a"]);
			
	  
	  		$("#spslide").carouFredSel({
			items		: 1,
			auto :false,
			prev : "#toi-bt",
		    next : "#lui-bt",
			pagination	: {
				container		: ".thumnails",
				anchorBuilder	: function( nr, item ) {
					var src = $(item).find('img').attr( "src" );
						src = src.replace( "/large/", "/small/");
					return '<img src="' + src + '" />';
				}
			}		
			
		});
			  		$(".dt-inner > div").carouFredSel({
			items		: 4,
			auto :true,
			prev : ".dt-next",
		    next : ".dt-prev",
			scroll:{ items:1}
		});
		
		
		
		//trang san pham  hien thi san pham thumnails
		
		$(".thumnails").carouFredSel({
			items		: 4,
			auto :false
		});
		
		//formdathang
		
		$('#dathang-bt').click(
		
			function(){
				if($('#formdathang').height() == 0){
				$('#formdathang').animate({height:405 +'px'},1000)
				}
				else{$('#formdathang').animate({height:0},1000)}
				});


		//LightBox
		$('#spslide a').lightBox();   

	 
	 
	 
$('.active').find('ul').show();
$('.sp a').hover(function(){
	$(this).parent().find('img.normal').show(200);},
	function(){
	$(this).parent().find('img.normal').hide(200);
	})
$('.sp a').mousemove(function(e){
      var ngang = e.pageX; 
	  var doc = e.pageY + 1;
	  $(this).parent().find('img.normal').css('top',doc + 5 + 'px');
	  $(this).parent().find('img.normal').css('left',ngang + 5 + 'px');
   }); 
	
	
	
	$('#foo3_pag').hide();
	$('#ontop-content').hover(function(){
		$('#foo3_pag').fadeIn()},
		function(){
		$('#foo3_pag').fadeOut()	
			})
			
$('.list li:first').css('margin-top','10px'); 

		
	
});


function act(id) {
	element = document.getElementById('item'+id);
	if(!element.className) {
		element.className = 'active-menu';
	} else {
		newClassName = element.className;
		newClassName+= " ";
		newClassName+= 'active-menu';
		element.className = newClassName;
	}
}

function sideAct(id) {
	element = document.getElementById(id);
	if(!element.className) {
		element.className = 'active';
	} else {
		newClassName = element.className;
		newClassName+= " ";
		newClassName+= 'active';
		element.className = newClassName;
	}
}